package com.example.rpc_easy.servers;


import io.vertx.core.Vertx;

public class HttpServerImpl implements HttpServer {
    /**
     * 启动服务
     * @param port
     */
    @Override
    public void startService(int port) {
        //创建vertx实例
        Vertx vertx = Vertx.vertx();

        //创建HTTP服务器
        io.vertx.core.http.HttpServer httpServer = vertx.createHttpServer();
//        //通过创建的服务器来监听端口并处理请求
//        httpServer.requestHandler(request->{
//            //处理Http请求
//            System.out.println("收到请求"+request.method()+""+request.uri());
//            //发送Http响应
//            request.response()
//                    .putHeader("content-type","text/plain")
//                    .end("发送响应");
//        });
       httpServer.requestHandler(new HttpServerHandle());

        //启动监听服务器并监听指定端口
        httpServer.listen(port)
                .onSuccess(server -> System.out.println("服务器启动成功"+port))
                .onFailure(err -> System.err.println("失败: " + err.getMessage()));
    }



}
